/*******************************************************************************
  PROJECT: Digital Video Use, Emotional Well-Being, and Fertility Intentions
  FILE:    Master_Analysis.do
  AUTHOR:  [Your Name/Author Name]
  DATE:    December 2025
  
  DESCRIPTION:
  This do-file performs the complete analysis for the study, including:
  1. Data cleaning and variable recoding.
  2. Descriptive statistics (Table 1).
  3. Main Stratified Multinomial Logistic Regression Models (Tables 2 & 3).
  4. Generation of Predicted Probability Figures (Figure 1 & 2).
  5. Pooled 3-way Interaction Tests (Supplementary Table A4).
  6. Sensitivity Analysis using Binary Outcomes.

  INSTRUCTIONS:
  - Update the "global data_path" and "global fig_path" before running.
  - Requires the Monitoring the Future (MTF) dataset.
*******************************************************************************/

clear all
set more off
capture log close

*-------------------------------------------------------------------------------
* 0. SETTINGS & PATHS
*-------------------------------------------------------------------------------

* [USER ACTION REQUIRED] Set your local paths here
global data_path "C:/Path/To/Your/Data" 
global fig_path  "C:/Path/To/Your/Figures"

* Load Data
use "$data_path/Social_Media_Fertility_Weight_2018-2023.dta", clear

* Set Survey Weights
svyset [pweight = ARCHIVE_WT]


*-------------------------------------------------------------------------------
* 1. VARIABLE RECODING
*-------------------------------------------------------------------------------

*** 1.1 Dependent Variable: Fertility Intentions (3 Categories) ***
capture drop Desired_Children_Recode_new
gen Desired_Children_Recode_new = .
replace Desired_Children_Recode_new = 1 if inlist(Desired_Children, 1)          // 0 Children
replace Desired_Children_Recode_new = 2 if inlist(Desired_Children, 2,3,4,5,6,7) // 1+ Children
replace Desired_Children_Recode_new = 3 if Desired_Children == 8                // Don't Know

label define Desired_Children_lbl_new 1 "0 Children" 2 "1+ Children" 3 "Don't Know"
label values Desired_Children_Recode_new Desired_Children_lbl_new

*** 1.2 Demographic Variables ***

* Gender (1=Boys, 2=Girls)
capture drop Gender_Recode
gen Gender_Recode = .
replace Gender_Recode = 1 if Gender == 1
replace Gender_Recode = 2 if Gender == 2
label define Gender_lbl 1 "Boys" 2 "Girls"
label values Gender_Recode Gender_lbl

* COVID Period (1=Pre-2020, 2=Post-2021+)
capture drop Covid_Period
gen Covid_Period = .
replace Covid_Period = 1 if Survey_Year <= 2020
replace Covid_Period = 2 if Survey_Year > 2020
label define Covid_Period_lbl 1 "Pre-COVID" 2 "Post-COVID"
label values Covid_Period Covid_Period_lbl

* Happiness (Binary)
capture drop Happiness_Binary
gen Happiness_Binary = .
replace Happiness_Binary = 1 if Happiness_Level == 1            // Not happy (reference)
replace Happiness_Binary = 2 if inlist(Happiness_Level, 2,3)    // Pretty / Very happy
label define HappyBinary 1 "Not Happy" 2 "Happy"
label values Happiness_Binary HappyBinary

*** 1.3 Media Use Variables (Original 4-cat Recode) ***
foreach var in Weekday_Video_Hours Weekend_Video_Hours Social_Media_Hours Gaming_Hours {
    capture drop `var'_Cat
    gen `var'_Cat = .
    replace `var'_Cat = 1 if `var' == 1
    replace `var'_Cat = 2 if `var' == 2
    replace `var'_Cat = 3 if inlist(`var', 3, 4)
    replace `var'_Cat = 4 if inlist(`var', 5, 6, 7)
}

*** 1.4 Main Independent Variables (3-Category Recode) ***
* Video Use: 1=None, 2=Low/Mod, 3=Heavy (5+ hrs)
capture drop Weekday_Video_Hours_Cat3 Weekend_Video_Hours_Cat3
gen Weekday_Video_Hours_Cat3 = .
replace Weekday_Video_Hours_Cat3 = 1 if Weekday_Video_Hours_Cat == 1
replace Weekday_Video_Hours_Cat3 = 2 if inlist(Weekday_Video_Hours_Cat, 2, 3)
replace Weekday_Video_Hours_Cat3 = 3 if Weekday_Video_Hours_Cat == 4

gen Weekend_Video_Hours_Cat3 = .
replace Weekend_Video_Hours_Cat3 = 1 if Weekend_Video_Hours_Cat == 1
replace Weekend_Video_Hours_Cat3 = 2 if inlist(Weekend_Video_Hours_Cat, 2, 3)
replace Weekend_Video_Hours_Cat3 = 3 if Weekend_Video_Hours_Cat == 4

label define Video_3cat 1 "None" 2 "Low/Moderate" 3 "Heavy (5+hrs)"
label values Weekday_Video_Hours_Cat3 Video_3cat
label values Weekend_Video_Hours_Cat3 Video_3cat

* Gaming Use (Control): 3 Categories
capture drop Gaming_Hours_Cat3
gen Gaming_Hours_Cat3 = .
replace Gaming_Hours_Cat3 = 1 if Gaming_Hours_Cat == 1
replace Gaming_Hours_Cat3 = 2 if inlist(Gaming_Hours_Cat, 2, 3)
replace Gaming_Hours_Cat3 = 3 if Gaming_Hours_Cat == 4
label define Gaming_3cat 1 "None" 2 "Low/Moderate" 3 "Heavy (5+hrs)"
label values Gaming_Hours_Cat3 Gaming_3cat

*** 1.5 Control Variables ***

* Race
capture drop Race_Recode
gen Race_Recode = .
replace Race_Recode = 1 if Race == 1             // Black
replace Race_Recode = 2 if Race == 2             // White
replace Race_Recode = 3 if Race == 3             // Hispanic
replace Race_Recode = 4 if Race > 3 | Race == .  // Others/NA

* City Size
capture drop City_Size_Recode
gen City_Size_Recode = .
replace City_Size_Recode = 1 if inlist(City_Size, 2,3)          // Rural
replace City_Size_Recode = 2 if inlist(City_Size, 4,5,6)        // Small/Med
replace City_Size_Recode = 3 if inlist(City_Size, 7,8,9,10)     // Large
replace City_Size_Recode = 4 if City_Size == 1 | City_Size == . // DK/NA

* Living Arrangement
capture drop Combined_Living_Arrangement
gen Combined_Living_Arrangement = .
replace Combined_Living_Arrangement = 1 if Lives_with_Mother == 2 & Lives_with_Father == 2
replace Combined_Living_Arrangement = 2 if Lives_with_Mother != 2 & Lives_with_Father == 2
replace Combined_Living_Arrangement = 3 if Lives_with_Mother == 2 & Lives_with_Father != 2
replace Combined_Living_Arrangement = 4 if (Lives_with_Mother != 2 & Lives_with_Father != 2) ///
                                         | (Lives_with_Mother == . & Lives_with_Father == .)

* Political Beliefs
capture drop Poli_Beli_grp
gen Poli_Beli_grp = .
replace Poli_Beli_grp = 1 if inlist(Poli_Beli, 1,2)    // Conservative
replace Poli_Beli_grp = 2 if Poli_Beli == 3            // Moderate
replace Poli_Beli_grp = 3 if inlist(Poli_Beli, 4,5,6)  // Liberal
replace Poli_Beli_grp = 4 if Poli_Beli == 7            // None/DK

* Dating Frequency
capture drop Date_Wk_Recode_3cat
gen Date_Wk_Recode_3cat = .
replace Date_Wk_Recode_3cat = 1 if Date_Wk == 1
replace Date_Wk_Recode_3cat = 2 if inlist(Date_Wk, 2,3)
replace Date_Wk_Recode_3cat = 3 if inlist(Date_Wk, 4,5,6)

* Sample Restriction: Keep only valid Gender responses
keep if inlist(Gender_Recode, 1, 2)


*-------------------------------------------------------------------------------
* 2. TABLE 1: DESCRIPTIVE STATISTICS
*-------------------------------------------------------------------------------

* Define Groups for Descriptive Table
capture drop Table1_Group
capture label drop T1_Group_lbl
gen Table1_Group = .
replace Table1_Group = 1 if Gender_Recode == 1 & Covid_Period == 1
replace Table1_Group = 2 if Gender_Recode == 1 & Covid_Period == 2
replace Table1_Group = 3 if Gender_Recode == 2 & Covid_Period == 1
replace Table1_Group = 4 if Gender_Recode == 2 & Covid_Period == 2
label define T1_Group_lbl 1 "Boys (Pre)" 2 "Boys (Post)" 3 "Girls (Pre)" 4 "Girls (Post)"
label values Table1_Group T1_Group_lbl

di _n(3) "================== TABLE 1: DISTRIBUTIONS =================="

* 2.1 Categorical Variables
local all_cat_vars Desired_Children_Recode_new ///
                   Weekday_Video_Hours_Cat3 Weekend_Video_Hours_Cat3 ///
                   Happiness_Binary ///
                   Race_Recode Mother_Education Father_Education ///
                   Social_Media_Hours_Cat Gaming_Hours_Cat3 ///
                   Religion_Importance Date_Wk_Recode_3cat ///
                   City_Size_Recode Combined_Living_Arrangement ///
                   Poli_Beli_grp

foreach v of local all_cat_vars {
    di _n "Variable: `v'"
    svy: tab `v' Table1_Group, col
}

* 2.2 Continuous Variables
di _n(3) "================== TABLE 1: MEANS =================="
svy: mean Siblings, over(Table1_Group)

* 2.3 Pre vs Post Significance Tests
di _n(3) "================== PRE vs POST TESTS (p-values) =================="
local key_test_vars Desired_Children_Recode_new ///
                    Weekday_Video_Hours_Cat3 Weekend_Video_Hours_Cat3 ///
                    Happiness_Binary

foreach v of local key_test_vars {
    di _n ">>> Variable: `v'"
    di "Boys: Pre vs Post"
    svy: tab `v' Covid_Period if Gender_Recode == 1
    
    di "Girls: Pre vs Post"
    svy: tab `v' Covid_Period if Gender_Recode == 2
}

di _n "Siblings – Boys: Pre vs Post"
svy: regress Siblings i.Covid_Period if Gender_Recode == 1
test


*-------------------------------------------------------------------------------
* 3. MAIN MODELS & FIGURES (Stratified by Gender & Period)
* Outcome: Fertility Intentions (Multinomial Logit)
*-------------------------------------------------------------------------------

* Note: Base outcome = 1 (0 Children)

// =============================================================================
//  3.1 BOYS (Gender_Recode == 1)
// =============================================================================

*** A) Boys: Pre-COVID / Weekday Video ***
di _n ">>> [BOYS] Pre-COVID / Weekday Video Analysis"
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekday_Video_Hours_Cat3 ///
    i.Weekend_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 1 & Covid_Period == 1, baseoutcome(1)
est store boys_pre_wd

* Marginal Effects for Table 2
margins Happiness_Binary, dydx(Weekday_Video_Hours_Cat3) predict(outcome(2)) post 

* Figure Generation
est restore boys_pre_wd
margins i.Happiness_Binary, at(Weekday_Video_Hours_Cat3=(1 2 3)) predict(outcome(2)) post 
marginsplot, noci xdimension(Weekday_Video_Hours_Cat3) ///
    xtitle("Weekday Video (1=None, 2=Low/Mod, 3=Heavy)") ///
    ytitle("Pr(1+ Child)") ///
    title("Boys, Pre-COVID: Weekday Video") ///
    legend(order(1 "Not happy" 2 "Happy"))
graph export "$fig_path/Fig_Boys_Pre_WD_Pr1Plus.png", replace


*** B) Boys: Post-COVID / Weekday Video ***
di _n ">>> [BOYS] Post-COVID / Weekday Video Analysis"
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekday_Video_Hours_Cat3 ///
    i.Weekend_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 1 & Covid_Period == 2, baseoutcome(1)
est store boys_post_wd

* Marginal Effects for Table 2
margins Happiness_Binary, dydx(Weekday_Video_Hours_Cat3) predict(outcome(2)) post 

* Figure Generation
est restore boys_post_wd
margins i.Happiness_Binary, at(Weekday_Video_Hours_Cat3=(1 2 3)) predict(outcome(2)) post
marginsplot, noci xdimension(Weekday_Video_Hours_Cat3) ///
    xtitle("Weekday Video (1=None, 2=Low/Mod, 3=Heavy)") ///
    ytitle("Pr(1+ Child)") ///
    title("Boys, Post-COVID: Weekday Video") ///
    legend(order(1 "Not happy" 2 "Happy"))
graph export "$fig_path/Fig_Boys_Post_WD_Pr1Plus.png", replace


*** C) Boys: Pre-COVID / Weekend Video ***
di _n ">>> [BOYS] Pre-COVID / Weekend Video Analysis"
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekend_Video_Hours_Cat3 ///
    i.Weekday_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 1 & Covid_Period == 1, baseoutcome(1)
est store boys_pre_we

* Marginal Effects for Table 2
margins Happiness_Binary, dydx(Weekend_Video_Hours_Cat3) predict(outcome(2)) post 

* Figure Generation
est restore boys_pre_we
margins i.Happiness_Binary, at(Weekend_Video_Hours_Cat3=(1 2 3)) predict(outcome(2)) post
marginsplot, noci xdimension(Weekend_Video_Hours_Cat3) ///
    xtitle("Weekend Video (1=None, 2=Low/Mod, 3=Heavy)") ///
    ytitle("Pr(1+ Child)") ///
    title("Boys, Pre-COVID: Weekend Video") ///
    legend(order(1 "Not happy" 2 "Happy"))
graph export "$fig_path/Fig_Boys_Pre_WE_Pr1Plus.png", replace


*** D) Boys: Post-COVID / Weekend Video ***
di _n ">>> [BOYS] Post-COVID / Weekend Video Analysis"
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekend_Video_Hours_Cat3 ///
    i.Weekday_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 1 & Covid_Period == 2, baseoutcome(1)
est store boys_post_we

* Marginal Effects for Table 2
margins Happiness_Binary, dydx(Weekend_Video_Hours_Cat3) predict(outcome(2)) post 

* Figure Generation
est restore boys_post_we
margins i.Happiness_Binary, at(Weekend_Video_Hours_Cat3=(1 2 3)) predict(outcome(2)) post
marginsplot, noci xdimension(Weekend_Video_Hours_Cat3) ///
    xtitle("Weekend Video (1=None, 2=Low/Mod, 3=Heavy)") ///
    ytitle("Pr(1+ Child)") ///
    title("Boys, Post-COVID: Weekend Video") ///
    legend(order(1 "Not happy" 2 "Happy"))
graph export "$fig_path/Fig_Boys_Post_WE_Pr1Plus.png", replace


// =============================================================================
//  3.2 GIRLS (Gender_Recode == 2)
// =============================================================================

*** A) Girls: Pre-COVID / Weekday Video ***
di _n ">>> [GIRLS] Pre-COVID / Weekday Video Analysis"
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekday_Video_Hours_Cat3 ///
    i.Weekend_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 2 & Covid_Period == 1, baseoutcome(1)
est store girls_pre_wd

* Marginal Effects for Table 3
margins Happiness_Binary, dydx(Weekday_Video_Hours_Cat3) predict(outcome(2)) post 

* Figure Generation
est restore girls_pre_wd
margins i.Happiness_Binary, at(Weekday_Video_Hours_Cat3=(1 2 3)) predict(outcome(2)) post
marginsplot, noci xdimension(Weekday_Video_Hours_Cat3) ///
    xtitle("Weekday Video (1=None, 2=Low/Mod, 3=Heavy)") ///
    ytitle("Pr(1+ Child)") ///
    title("Girls, Pre-COVID: Weekday Video") ///
    legend(order(1 "Not happy" 2 "Happy"))
graph export "$fig_path/Fig_Girls_Pre_WD_Pr1Plus.png", replace


*** B) Girls: Post-COVID / Weekday Video ***
di _n ">>> [GIRLS] Post-COVID / Weekday Video Analysis"
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekday_Video_Hours_Cat3 ///
    i.Weekend_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 2 & Covid_Period == 2, baseoutcome(1)
est store girls_post_wd

* Marginal Effects for Table 3
margins Happiness_Binary, dydx(Weekday_Video_Hours_Cat3) predict(outcome(2)) post 

* Figure Generation
est restore girls_post_wd
margins i.Happiness_Binary, at(Weekday_Video_Hours_Cat3=(1 2 3)) predict(outcome(2)) post
marginsplot, noci xdimension(Weekday_Video_Hours_Cat3) ///
    xtitle("Weekday Video (1=None, 2=Low/Mod, 3=Heavy)") ///
    ytitle("Pr(1+ Child)") ///
    title("Girls, Post-COVID: Weekday Video") ///
    legend(order(1 "Not happy" 2 "Happy"))
graph export "$fig_path/Fig_Girls_Post_WD_Pr1Plus.png", replace


*** C) Girls: Pre-COVID / Weekend Video ***
di _n ">>> [GIRLS] Pre-COVID / Weekend Video Analysis"
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekend_Video_Hours_Cat3 ///
    i.Weekday_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 2 & Covid_Period == 1, baseoutcome(1)
est store girls_pre_we

* Marginal Effects for Table 3
margins Happiness_Binary, dydx(Weekend_Video_Hours_Cat3) predict(outcome(2)) post 

* Figure Generation
est restore girls_pre_we
margins i.Happiness_Binary, at(Weekend_Video_Hours_Cat3=(1 2 3)) predict(outcome(2)) post
marginsplot, noci xdimension(Weekend_Video_Hours_Cat3) ///
    xtitle("Weekend Video (1=None, 2=Low/Mod, 3=Heavy)") ///
    ytitle("Pr(1+ Child)") ///
    title("Girls, Pre-COVID: Weekend Video") ///
    legend(order(1 "Not happy" 2 "Happy"))
graph export "$fig_path/Fig_Girls_Pre_WE_Pr1Plus.png", replace


*** D) Girls: Post-COVID / Weekend Video ***
di _n ">>> [GIRLS] Post-COVID / Weekend Video Analysis"
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekend_Video_Hours_Cat3 ///
    i.Weekday_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 2 & Covid_Period == 2, baseoutcome(1)
est store girls_post_we

* Marginal Effects for Table 3
margins Happiness_Binary, dydx(Weekend_Video_Hours_Cat3) predict(outcome(2)) post 

* Figure Generation
est restore girls_post_we
margins i.Happiness_Binary, at(Weekend_Video_Hours_Cat3=(1 2 3)) predict(outcome(2)) post
marginsplot, noci xdimension(Weekend_Video_Hours_Cat3) ///
    xtitle("Weekend Video (1=None, 2=Low/Mod, 3=Heavy)") ///
    ytitle("Pr(1+ Child)") ///
    title("Girls, Post-COVID: Weekend Video") ///
    legend(order(1 "Not happy" 2 "Happy"))
graph export "$fig_path/Fig_Girls_Post_WE_Pr1Plus.png", replace


*-------------------------------------------------------------------------------
* 4. POOLED 3-WAY INTERACTION TESTS (Supplementary Table A4)
* Test: Happiness × Media × Covid
*-------------------------------------------------------------------------------

di _n(2) "================== TABLE A4: 3-WAY INTERACTIONS =================="

*----------- BOYS: Weekday Video 3-way -----------*
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekday_Video_Hours_Cat3##ib1.Covid_Period ///
    i.Weekend_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 1, baseoutcome(1)
est store boys_wd_3way

testparm i.Happiness_Binary#i.Weekday_Video_Hours_Cat3#i.Covid_Period
margins i.Happiness_Binary#ib1.Covid_Period, dydx(Weekday_Video_Hours_Cat3) post

*----------- BOYS: Weekend Video 3-way -----------*
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekend_Video_Hours_Cat3##ib1.Covid_Period ///
    i.Weekday_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 1, baseoutcome(1)
est store boys_we_3way

testparm i.Happiness_Binary#i.Weekend_Video_Hours_Cat3#i.Covid_Period
margins i.Happiness_Binary#ib1.Covid_Period, dydx(Weekend_Video_Hours_Cat3) post

*----------- GIRLS: Weekday Video 3-way -----------*
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekday_Video_Hours_Cat3##ib1.Covid_Period ///
    i.Weekend_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 2, baseoutcome(1)
est store girls_wd_3way

testparm i.Happiness_Binary#i.Weekday_Video_Hours_Cat3#i.Covid_Period
margins i.Happiness_Binary#ib1.Covid_Period, dydx(Weekday_Video_Hours_Cat3) post

*----------- GIRLS: Weekend Video 3-way -----------*
mlogit Desired_Children_Recode_new ///
    i.Happiness_Binary##ib1.Weekend_Video_Hours_Cat3##ib1.Covid_Period ///
    i.Weekday_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    [pweight = ARCHIVE_WT] ///
    if Gender_Recode == 2, baseoutcome(1)
est store girls_we_3way

testparm i.Happiness_Binary#i.Weekend_Video_Hours_Cat3#i.Covid_Period
margins i.Happiness_Binary#ib1.Covid_Period, dydx(Weekend_Video_Hours_Cat3) post


*-------------------------------------------------------------------------------
* 5. SENSITIVITY ANALYSIS: BINARY OUTCOME
* Outcome: 1 = 1+ Child, 0 = 0 Child or Don't Know
*-------------------------------------------------------------------------------

di _n(2) "================== SENSITIVITY ANALYSIS (BINARY OUTCOME) =================="

preserve

* 5.1 Create Binary Variable
capture drop Desire_1plus_bin
gen Desire_1plus_bin = .
replace Desire_1plus_bin = 0 if inlist(Desired_Children_Recode_new, 1, 3) // 0 Child or Don't Know
replace Desire_1plus_bin = 1 if Desired_Children_Recode_new == 2          // 1+ Children

label define Desire_1plus_lab 0 "0 Child or DK" 1 "1+ Child"
label values Desire_1plus_bin Desire_1plus_lab

* 5.2 Boys (Post-COVID) Sensitivity Model
di _n ">>> Sensitivity: Boys, Post-COVID"
svy: logit Desire_1plus_bin ///
    i.Happiness_Binary##ib1.Weekday_Video_Hours_Cat3 ///
    i.Weekend_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    if Gender_Recode == 1 & Covid_Period == 2

* 5.3 Girls (Post-COVID) Sensitivity Model
di _n ">>> Sensitivity: Girls, Post-COVID"
svy: logit Desire_1plus_bin ///
    i.Happiness_Binary##ib1.Weekday_Video_Hours_Cat3 ///
    i.Weekend_Video_Hours_Cat3 ///
    i.Race_Recode i.Religion_Importance i.City_Size_Recode ///
    i.Combined_Living_Arrangement i.Poli_Beli_grp i.Date_Wk_Recode_3cat ///
    i.Social_Media_Hours_Cat i.Gaming_Hours_Cat3 ///
    Mother_Education Father_Education Siblings ///
    i.Survey_Year ///
    if Gender_Recode == 2 & Covid_Period == 2

restore


*-------------------------------------------------------------------------------
* 6. POST-ESTIMATION CHECKS (Distribution & Cell Counts)
*-------------------------------------------------------------------------------

di _n(2) "================== DISTRIBUTION CHECKS =================="

* Check distribution for Boys, Post-COVID (Weighted)
table Happiness_Binary Weekday_Video_Hours_Cat3 Desired_Children_Recode_new ///
    if Gender_Recode == 1 & Covid_Period == 2 [pw = ARCHIVE_WT], ///
    statistic(frequency) nformat(%9.0f)

* Check for small cell sizes (Don't Know response)
tab Happiness_Binary Weekday_Video_Hours_Cat3 ///
    if Gender_Recode == 1 & Covid_Period == 2 & Desired_Children_Recode_new == 3, ///
    missing

di _n(3) "================== ANALYSIS COMPLETE =================="